﻿using System;
using BO.Video;
using BO.Infrastructure.StaticData;
using BO.Infrastructure.Utils;

namespace GUI.Controls.Video
{
    public partial class HighlightVideo2 : System.Web.UI.UserControl
    {
        private const int Width = 638;
        private const int Height = 369;
        private const string PublishedDateFormat = "HH:mm:ss dd/MM/yyyy";
        public string EmbedCode { get; set; }
        public int ZoneId { get; set; }

        protected void Page_Load(object sender, EventArgs e)
        {
            var dt = VideoBO.GetVideoByMode(1, DefinedConstants.Video.Mode.NoiBat, ZoneId);
            Visible = DataBind(dt);
        }

        private bool DataBind(System.Data.DataTable dt)
        {
            if (dt != null && dt.Rows.Count > 0)
            {
                var r = dt.Rows[0];
                ltrTitle.Text = r[SqlConstants.Video.Name].ToString();
                ltrPublishedDate.Text =
                    PresentationUtils.Object2DateTime(r[SqlConstants.Video.PublishDate].ToString()).ToString(
                        PublishedDateFormat);
                ltrEmbedCode.Text = PresentationUtils.Video.BuildEmbedCode(
                    r[SqlConstants.Video.KeyVideo].ToString(),
                    r[SqlConstants.Video.PName].ToString(),
                    Width,
                    Height,
                    r[SqlConstants.Video.Avatar].ToString());
                return true;
            }
            return false;
        }
    }
}